<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${packageName}.mapper.${ classPre }MapperEx">

	<resultMap id="BaseResultMap" type="${packageName}.model.db.${ classPre }" >
	</resultMap>

    <resultMap id="BaseResultMapVO" type="${packageName}.model.vo.${ classPre }VO" extends="BaseResultMap">
    </resultMap>

    <sql id="Base_Column_List" >
	<#list properties as pro>
		<#if pro_index == properties?size-1>
		entity.${pro.columnName}
		<#else>
		entity.${pro.columnName},
		</#if>
	</#list>
    </sql>

    <select id="loadVOById" resultMap="BaseResultMapVO">
        select <include refid="Base_Column_List"/>
          from ${tableName?lower_case} entity
         where entity.id = ${r"#{id}"}
        <#if hasArchive>
           and entity.archive = false
        </#if>
    </select>

    <select id="list" resultMap="BaseResultMapVO">
        select <include refid="Base_Column_List"/>
          from ${tableName?lower_case} entity
         where 1=1
        <#list tableConfig.searchFields as searchField>
            <#if fieldMap[searchField.fieldName].proType == 'String'>
        <if test="query.${searchField.searchName} != null and query.${searchField.searchName} != ''">
            <#else>
        <if test="query.${searchField.searchName} != null">
            </#if>
            <#if searchField.condMark == '='>
            and entity.${searchField.fieldName} = ${'#'}{query.${searchField.searchName}}
            <#elseif searchField.condMark == '!='>
            and entity.${searchField.fieldName} != ${'#'}{query.${searchField.searchName}}
            <#elseif searchField.condMark == 'like'>
            and entity.${searchField.fieldName} like CONCAT('%',${'#'}{query.${searchField.searchName}},'%')
            <#elseif searchField.condMark == '>'>
            and entity.${searchField.fieldName} > ${'#'}{query.${searchField.searchName}}
            <#elseif searchField.condMark == '<'>
            and <![CDATA[entity.${searchField.fieldName} < ${'#'}{query.${searchField.searchName}}]]>
            <#elseif searchField.condMark == '>='>
            and entity.${searchField.fieldName} >= ${'#'}{query.${searchField.searchName}}
            <#elseif searchField.condMark == '<='>
            and <![CDATA[entity.${searchField.fieldName} <= ${'#'}{query.${searchField.searchName}}]]>
            </#if>
        </if>
        </#list>
        <#if hasArchive>
            and entity.archive = false
        </#if>
    </select>
</mapper>